# -*- coding: utf-8 -*-
import pandas as pd
import csv


def iter_rows_csv(filename, delimiter=','):  # 读取csv的二维数组，第一行是列名
    """
    :param filename: csv文件路径
    :param delimiter: 分隔符，包括 ','; '\t'; '\n' 等
    :return: [[列名], ['第一行值], ['第二行值], ...]
    """
    iteration = []
    with open(filename, 'r') as csvfile:
        reader = csv.reader(csvfile, delimiter=delimiter)
        for row in reader:
            iteration.append(row)
    return iteration


def read_csv_by_column(filename, col_name, delimiter=','):  # 读取csv列名对应列，不包括列名
    """
    :param filename: csv文件路径
    :param col_name: 列名
    :param delimiter: 分隔符，包括 ','; '\t'; '\n' 等
    :return: 如列名为A：['A1', 'A2', ..., 'An']
    """
    df = pd.read_csv(filename, delimiter=delimiter)
    col_values = df.loc[:, col_name].values
    return col_values
